#include<bits/stdc++.h>
using namespace std;
#define int long long

struct node {
	int w, s;
} a[300005];

signed main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i].w >> a[i].s;

	sort(a + 1, a + n + 1, [](node x, node y) {
		return x.w - y.s < y.w - x.s;
	});

	int ans = -1e9, pre = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, pre - a[i].s);
		pre += a[i].w;
	}
	cout << ans;
	return 0;
}
